<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录注册页面</title>
<link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
     <div class="materialContainer">
	<div class="box">
		<div class="title">登录</div>
		<div class="input">
			<label for="name">用户名</label>
			<input type="text" name="name" id="name">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="pass">密码</label>
			<input type="password" name="pass" id="pass">
			<span class="spin"></span>
		</div>
		<div class="button login" id="btn_login">
			<button>
				<span>登录</span>
				<i class="fa fa-check"></i>
			</button>
		</div>
		<a href="javascript:" class="pass-forgot">忘记密码？</a>
	</div>

	<div class="overbox">
		<div class="material-button alt-2">
			<span class="shape"></span>
		</div>
		<div class="title">注册</div>
		<div class="input">
			<label for="regname">用户名</label>
			<input type="text" name="regname" id="regname">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="regpass">密码</label>
			<input type="password" name="regpass" id="regpass">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="reregpass">确认密码</label>
			<input type="password" name="reregpass" id="reregpass">
			<span class="spin"></span>
		</div>
		<div class="button" id="btn_rsg">
			<button>
				<span>注册</span>
			</button>
		</div>
	</div>

</div>
<script src="js/jquery.min.js"></script>
<script src="js/index.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript">
     //登录
       $("#btn_login").click(function(){
    	   //alert("注册");
    	   var username = $("#name").val();    	   
    	   var password = $("#pass").val();
    	   $.ajax({
    		   url:'/lvyou/LoginServlet',
    		   type:'post',
    		   data:'username='+username+"&password="+password,
    		   success:function(data){
    			   console.log(data);
    			   if(JSON.parse(data).code==100){
    				   showMessage('登录成功','success',1000)
    				   localStorage.setItem("userId",JSON.parse(data).extend.id);
    				   //添加访问量 
    				   updatecishu();
    				   window.location.href="index.html";
    			   }else{
    				   showMessage('登录失败','error',1000)
    			   }
    		   }
    	   });
       });
     
      function updatecishu(){
    	  $.ajax({
   		   url:'/lvyou/AddfangkeshuServlet',
   		   type:'post',
   		   success:function(data){
   			   
   		   }
   	   }); 
      }
     
     //注册
       $("#btn_rsg").click(function(){
    	  // alert("注册");
    	   var username = $("#regname").val();
    	   var password = $("#regpass").val();
    	   var password2 = $("#reregpass").val();
    	   if(password!=password2){
    		   showMessage('两次密码不一样','error',1000)
    	   }
    	   $.ajax({
    		   url:'/lvyou/RsgServlet',
    		   type:'post',
    		   data:'username='+username+"&password="+password,
    		   success:function(data){
    			   console.log(data);
    			   if(JSON.parse(data).code==100){
    				   showMessage('注册成功','success',1000)
    			   }else{
    				   showMessage('账号已经被注册','error',1000)
    			   }
    		   }
    	   });
       });
</script>
</body>
</html>